package net.wy.commons.util;

public final class HTMLFilter {

	public static String filter(String message) {
		if (message == null) {
			return null;
		}
		
		char content[] = new char[message.length()];
		message.getChars(0, message.length(), content, 0);
		StringBuilder result = new StringBuilder(content.length + 50);
		for (int i = 0; i < content.length; i++) {
			switch (content[i]) {
			case '<':
				result.append("&lt;");
				break;
			case '>':
				result.append("&gt;");
				break;
			case '&':
				result.append("&amp;");
				break;
			case '"':
				result.append("&quot;");
				break;
			default:
				result.append(content[i]);
			}
		}
		return result.toString();//filterSensitive();
	}
	
	public static String filterSensitive(String msg) {
		String[] sensitive = new String[] {"屌", "逼", "屎", "尿", "娘", "shit", "fuck", "河蟹", "你妹", "共产党"};
		for (int i = 0; i < sensitive.length; i++) {
			if (msg.contains(sensitive[i])) {
				msg = msg.replaceAll(sensitive[i], "*");
			}
		}
		
		return msg;
	}
}
